import { Button } from 'antd';
import React from 'react';
import { connect } from 'umi';

import { fundStatisticsService as service } from '@/services/salaryManage/statistics';
import modelFactory from '@/pages/SalaryManage/Statistics/statisticsModelFactory';
import { commonColumn, amountColumn } from '@/pages/SalaryManage/utils/TableUtil';
import salaryStyle from '@/pages/SalaryManage/salaryManage.less';
import { goToSalaryStatisticsDetail } from '@/pages/SalaryManage/utils/pageNavigateUtil';
import EmptyPlaceHolder from '@/pages/SalaryManage/components/EmptyPlaceHolder';

const namespace = 'fundStatisticsModel';
const fundStatisticsModel = modelFactory.generateModel({ namespace, service });

const EmployeeSalaryCell = connect(
    ({ statisticsModel }) => ({ organizationCode: statisticsModel.selectOrganizationCode })
)(({ employeeName, employeeCode, organizationCode }) => <>{
    employeeName
        ? <Button
            type="link"
            className={salaryStyle.linkBtn}
            onClick={() => goToSalaryStatisticsDetail({ employeeCode, organizationCode })}
        >
            {employeeName}
        </Button>
        : <EmptyPlaceHolder />
}</>);

Object.assign(fundStatisticsModel.state, {
    title: '险金【汇总表】',
    subTitle: '',

    tableHeader: [
        commonColumn({
            title: '年月',
            dataIndex: 'yearMonth',
            width: 120,
            fixed: true
        }),
        {
            title: '姓名',
            dataIndex: 'employeeName',
            width: 100,
            fixed: true,
            render(text, record) {
                return (
                    <>
                        {
                            text || record.$$isSummary
                                ? <EmployeeSalaryCell employeeName={text} employeeCode={record.employeeCode} />
                                : <EmptyPlaceHolder />
                        }
                    </>
                );
            }
        },
        commonColumn({
            title: '工号',
            dataIndex: 'employeeNo',
            width: 100,
            fixed: true
        }),
        commonColumn({
            title: '证照号码',
            dataIndex: 'cardNo',
            width: 200
        }),
        commonColumn({
            title: '入职日期',
            dataIndex: 'startDateStr',
            align: 'center',
            width: 120
        }),
        commonColumn({
            title: '状态',
            dataIndex: 'statusName'
        }),
        commonColumn({
            title: '组织机构',
            dataIndex: 'departmentName',
            width: 150,
            ellipsis: true
        }),
        commonColumn({
            title: '岗位',
            dataIndex: 'dutyName',
            width: 150,
            ellipsis: true
        }),
        commonColumn({
            title: '职位',
            dataIndex: 'positionName',
            width: 150,
            ellipsis: true
        }),
        commonColumn({
            title: '职级',
            dataIndex: 'rankName',
            width: 150,
            ellipsis: true
        }),

        commonColumn({
            title: '城市',
            dataIndex: 'socialCityName'
        }),
        commonColumn({
            title: '社保方案',
            dataIndex: 'socialPlan',
            width: 250
        }),
        commonColumn({
            title: '起始缴纳月',
            dataIndex: 'socialStart',
            width: 110
        }),
        commonColumn({
            title: '最后缴纳月',
            dataIndex: 'socialEnd',
            width: 110
        }),
        amountColumn({
            title: '当月薪资',
            dataIndex: 'encryptTotalAmt'
        }),
        amountColumn({
            title: '当月绩效',
            dataIndex: 'kpiAmt'
        }),
        {
            title: '养老保险',
            dataIndex: 'old',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptOldBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'oldCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptOldCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'oldPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptOldPersonAmt'
                })
            ]
        },
        {
            title: '失业保险',
            dataIndex: 'unemploy',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptUnemployBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'unemployCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptUnemployCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'unemployPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptUnemployPersonAmt'
                })
            ]
        },
        {
            title: '工伤保险',
            dataIndex: 'harm',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptHarmBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'harmCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptHarmCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'harmPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptHarmPersonAmt'
                })
            ]
        },
        {
            title: '医疗保险',
            dataIndex: 'hospital',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptHospitalBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'hospitalCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptHospitalCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'hospitalPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptHospitalPersonAmt'
                })
            ]
        },
        {
            title: '生育保险',
            dataIndex: 'birth',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptBirthBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'birthCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptBirthCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'birthPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptBirthPersonAmt'
                })
            ]
        },
        {
            title: '大病保险',
            dataIndex: 'ill',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptIllBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'illCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptIllCompanyAmt'
                }),
                amountColumn({
                    title: '个人缴交比例',
                    dataIndex: 'illPersonRate'
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptIllPersonAmt'
                })
            ]
        },
        {
            title: '住房公积金',
            dataIndex: 'fund',
            children: [
                amountColumn({
                    title: '缴交基数',
                    dataIndex: 'encryptFundBaseAmt'
                }),
                commonColumn({
                    title: '单位缴交比例',
                    dataIndex: 'fundCompanyRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '单位缴交金额',
                    dataIndex: 'encryptFundCompanyAmt'
                }),
                commonColumn({
                    title: '个人缴交比例',
                    dataIndex: 'fundPersonRate',
                    className: salaryStyle.textRight
                }),
                amountColumn({
                    title: '个人缴交金额',
                    dataIndex: 'encryptFundPersonAmt'
                })
            ]
        },
        amountColumn({
            title: '单位缴交合计',
            dataIndex: 'encryptCompanyTotalAmt'
        }),
        amountColumn({
            title: '个人缴交合计',
            dataIndex: 'encryptPersonTotalAmt'
        })
    ],

    summaryFieldsRender: () => [
        { yearMonth: '合计' },
        'encryptTotalAmt',
        'kpiAmt',
        'encryptOldCompanyAmt',
        'encryptOldPersonAmt',
        'encryptUnemployCompanyAmt',
        'encryptUnemployPersonAmt',
        'encryptHarmCompanyAmt',
        'encryptHarmPersonAmt',
        'encryptHospitalCompanyAmt',
        'encryptHospitalPersonAmt',
        'encryptBirthCompanyAmt',
        'encryptBirthPersonAmt',
        'encryptIllCompanyAmt',
        'encryptIllPersonAmt',
        'encryptFundCompanyAmt',
        'encryptFundPersonAmt',
        'totalCompanyAmt',
        'totalPersonAmt',
        'encryptCompanyTotalAmt',
        'encryptPersonTotalAmt'
    ]
});

export default fundStatisticsModel;
